// pages/recruit/recruit.js
Page({

	/**
	 * 页面的初始数据
	 */
	data: {
		datalist:[]
	},
	onheaderClickLeft(){
		wx.navigateBack({})
	},
	handleDetailDel(event){
		var self = this;
		var id = event.target.dataset.id;
		wx.showModal({
			title:'删除提示',
			content:'删除后将无法恢复，确定删除？',
			success(res){
				if (res.confirm) {
					wx.request({
						url: 'https://www.grabinter.com/Works/deleteworks',
						method: 'POST',
						header: {
							"Content-Type": 'application/x-www-form-urlencoded'
						},
						data: {
							token:wx.getStorageSync('token'),
							id:id
						},
						success: json => {
							if(json.data.success){
								wx.showToast({
									title: '删除成功',
									icon: 'success',
									duration: 2000
								});
								var arr = self.data.datalist;
								var index = 0;
								for(var i in arr){
									if(parseInt(id) == parseInt(arr[i].id)){
										index = i;
									}
								}
								arr.splice(index,1);
								self.setData({
									datalist:arr
								})
							}else{
								wx.showToast({
									title: '删除失败',
									icon: 'error',
									duration: 2000
								});
							}
						}
					});
				}
			}
		})
	},
	handleDetailComplete(event){
		var self = this;
		var id = event.target.dataset.id;
		wx.showModal({
			title:'完成提示',
			content:'确定完成招聘？确认后这条招聘信息将不显示！',
			success(res){
				if (res.confirm) {
					wx.request({
						url: 'https://www.grabinter.com/Works/changworksstatus',
						method: 'POST',
						header: {
							"Content-Type": 'application/x-www-form-urlencoded'
						},
						data: {
							token:wx.getStorageSync('token'),
							id:id
						},
						success: json => {
							if(json.data.success){
								wx.showToast({
									title: '操作成功',
									icon: 'success',
									duration: 2000
								});
								var arr = self.data.datalist;
								var index = 0;
								for(var i in arr){
									if(parseInt(arr[i].id) == id){
										arr[i].status = 1;
									}
								}
								self.setData({
									datalist:arr
								})
							}else{
								wx.showToast({
									title: '操作失败',
									icon: 'error',
									duration: 2000
								});
							}
						}
					});
				}
			}
		})
	},
	getData(){
		var self = this;
		wx.showLoading({
			mask:true,
			title: '加载中',
		});
		wx.request({
			url: 'https://www.grabinter.com/Works/getworksbyuid',
			method: 'POST',
			header: {
				"Content-Type": 'application/x-www-form-urlencoded'
			},
			data: {
				token:wx.getStorageSync('token'),
			},
			success: json => {
				wx.hideLoading()
				if(json.data && json.data.data){
					
					self.setData({
						datalist:json.data.data
					});
				}else{
					wx.showToast({
						title: '数据获取失败',
						icon: 'error',
						duration: 2000
					})
				}
			}
		});
	},
	/**
	 * 生命周期函数--监听页面加载
	 */
	onLoad: function(options) {
		
		
		
	},
	handleDetail(){
		// wx.navigateTo({
		// 	url: '../indexdetail/indexdetail',
		// });
	},
	handleEditDetail(event){
		wx.navigateTo({
			url: '../recruitedit/recruitedit?id='+event.target.dataset.id,
		});
	},
	
	/**
	 * 生命周期函数--监听页面初次渲染完成
	 */
	onReady: function() {

	},

	/**
	 * 生命周期函数--监听页面显示
	 */
	onShow: function() {
		this.getData();
	},

	/**
	 * 生命周期函数--监听页面隐藏
	 */
	onHide: function() {

	},

	/**
	 * 生命周期函数--监听页面卸载
	 */
	onUnload: function() {

	},

	/**
	 * 页面相关事件处理函数--监听用户下拉动作
	 */
	onPullDownRefresh: function() {

	},

	/**
	 * 页面上拉触底事件的处理函数
	 */
	onReachBottom: function() {

	},

	/**
	 * 用户点击右上角分享
	 */
	onShareAppMessage: function() {

	}
})
